//
//  SinClassViewController.m
//  GSG
//
//  Created by dllo on 15/4/21.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "SinClassViewController.h"
#import "AFNetworking.h"
#import "MusicModel.h"
#import "UIImageView+WebCache.h"
#import "SinClassCell.h"
#import "SingerSongListViewController.h"
#import"PlayListViewController.h"
#import "MBProgressHUD.h"
@interface SinClassViewController ()<UITableViewDataSource,UITableViewDelegate>
@property(nonatomic,retain)NSMutableArray *modelArr;
@property (nonatomic,retain)UITableView *sinClassTableView;
@property(nonatomic,retain)MBProgressHUD*HUD;
@end


@implementation SinClassViewController
- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.modelArr = [NSMutableArray array];
    }

    return self;
}

- (void)data{

    NSString *str = [NSString stringWithFormat:@"http://v1.ard.tj.itlily.com/ttpod?a=getnewttpod&id=%ld&size=1000&page=1&app=ttpod&v=v7.7.0.2015012818&uid=&mid=iPhone4&f=f320&s=s310&imsi=&hid=&splus=7.1.1&active=1&net=2&openudid=ad6f50f586818c4f36ff4358053c1b53fee58cdf&idfa=E2EAC64B-1F1C-4AC5-A0E1-8BE37A03FB96&utdid=VTCyBQSkYzwDAALO9zZTFfPC&alf=201200",self.musicModel.id];
    


    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    [manager GET:str parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSDictionary *dict = responseObject;
        
        NSMutableArray *arr = [dict objectForKey:@"data"];
        for (NSInteger i=0; i<arr.count; i++) {
            
            MusicModel *movie = [[MusicModel alloc] init];
            NSMutableDictionary *movieDic = arr[i];
            [movie setValuesForKeysWithDictionary:movieDic];
            [self.modelArr addObject:movie];

                  }


//            NSLog(@"%@",arr);


        

        [self.sinClassTableView reloadData];
        [_HUD hide:YES];
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    }];
    
}
-(void)actionBuLand{
    PlayListViewController *plvc=[[PlayListViewController alloc]init];
    [self.navigationController pushViewController:plvc animated:YES];
    [plvc release];
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationItem.rightBarButtonItem=[[UIBarButtonItem alloc]initWithTitle:@"播放" style:UIBarButtonItemStyleDone target:self action:@selector(actionBuLand)];

    self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"bujing.png"]];
           [self data];
    self.sinClassTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) style:UITableViewStylePlain];
    [self.view addSubview:self.sinClassTableView];
    self.sinClassTableView.rowHeight = 100;
    self.sinClassTableView.backgroundColor = [UIColor clearColor];
    self.sinClassTableView.dataSource = self;
    self.sinClassTableView.delegate = self;
    self.title = self.musicModel.title;

    //小菊花
    //方式1.直接在View上show
    _HUD = [[MBProgressHUD showHUDAddedTo:self.view animated:YES] retain];
    
    
    //常用的设置
    //小矩形的背景色
    _HUD.color = [UIColor clearColor];//这儿表示无背景
    //显示的文字
    _HUD.labelText = @"提示";
    //细节文字
    _HUD.detailsLabelText = @"正在加载内容";
    //是否有庶罩
    _HUD.dimBackground = YES;

}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return  self.modelArr.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *reuse = @"reuse";
    SinClassCell *cell = [tableView dequeueReusableCellWithIdentifier:reuse];
    if (!cell) {
        cell = [[[SinClassCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuse] autorelease];
    }
    MusicModel *music = self.modelArr[indexPath.row];
    NSURL *url = [NSURL URLWithString:music.pic_url];
    [cell.pic_urlView sd_setImageWithURL:url];
    
    cell.singerNameLabel.text = music.singer_name;

    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    SingerSongListViewController *sslc=[[SingerSongListViewController alloc]init];
    [self.navigationController pushViewController:sslc animated:YES];
    MusicModel *music=self.modelArr[indexPath.row];
   
    sslc.music=music;

//    NSLog(@"%@",music.singer_id);
    [sslc release];

}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
